import request from '@/utils/request'
import qs from 'qs'

export function add(data) {
  return request({
    url: 'order/add',
    method: 'post',
    data
  })
}

export function del(ids) {
  return request({
    url: 'order/delete',
    method: 'delete',
    data: ids
  })
}

export function edit(data) {
  return request({
    url: 'order/update',
    method: 'put',
    data
  })
}

export function page(data) {
  return request({
    url: 'order/page',
    method: 'GET',
    data
  })
}

export function getOne(data) {
  return request({
    url: 'order/' + data,
    method: 'get',
    data
  })
}

export function update(data) {
  return request({
    url: 'order/update',
    method: 'PUT',
    data
  })
}

export function updateOrderNote(data) {
  return request({
    url: 'order/updateOrderNote',
    method: 'PUT',
    params: data
  })
}

export function complete(data) {
  return request({
    url: 'order/complete',
    method: 'PUT',
    params: data
  })
}

export function updateDeliveryTime(data) {
  return request({
    url: 'order/updateDeliveryTime',
    method: 'PUT',
    params: data
  })
}

export function refund(data) {
  return request({
    url: 'order/refund',
    method: 'PUT',
    params: data
  })
}

export function delivery(data) {
  return request({
    url: 'order/delivery',
    method: 'PUT',
    params: data
  })
}

export function flagComplaint(data) {
  return request({
    url: 'order/flagComplaint',
    method: 'PUT',
    params: data
  })
}
export function preSaleArrival(data) {
  return request({
    url: 'order/preSaleArrival',
    method: 'PUT',
    params: data
  })
}

export function all(data) {
  return request({
    url: 'order/all',
    method: 'GET',
    params: data
  })
}
export function printOrder(data) {
  return request({
    url: 'order/printOrder',
    method: 'put',
    params: data
  })
}
export function cancel(params) {
  return request({
    url: 'order/cancel',
    method: 'get',
    params: params
  })
}
export function cancelItem(params) {
  return request({
    url: 'order/cancelItem',
    method: 'put',
    params: params
  })
}
export function printReceipt(params) {
  return request({
    url: 'order/printReceipt' + '?' + qs.stringify(params, { indices: false }),
    method: 'get',
    responseType: 'blob'
  })
}

export function exportDeliveryOrder(data) {
  return request({
    url: 'order/exportDeliveryOrder' + '?' + qs.stringify(data, { indices: false }),
    method: 'GET',
    responseType: 'blob'
  })
}

export default {
  add,
  edit,
  del,
  page,
  getOne,
  complete,
  updateDeliveryTime,
  refund,
  updateOrderNote,
  delivery,
  all,
  flagComplaint,
  exportDeliveryOrder,
  preSaleArrival,
  printOrder,
  cancel,
  cancelItem,
  printReceipt
}
